#!/bin/bash

# 设置仓库目录
REMOTE_BRANCH="master"

if [ -n "$GIT_REMOTE" ]; then
    REMOTE_REPO="$GIT_REMOTE"
else
    # 如果没有设置GIT_REMOTE，则默认使用Gitee
    REMOTE_REPO="https://gitee.com/yyned2501/kf21.git"
fi

gitpull() {
    git reset --hard origin/"$REMOTE_BRANCH"
    git pull origin "$REMOTE_BRANCH"
}
# 检查是否是一个 Git 仓库
if [ ! -d ".git" ]; then
    git init
    git remote add origin "$REMOTE_REPO"
    git fetch origin >/dev/null
    gitpull
fi
while true; do
    git fetch origin >/dev/null
    if [ $(git rev-list --count --right-only HEAD...origin/"$REMOTE_BRANCH") -gt 0 ]; then
        gitpull
        if [ -f client/setconfig.py ]; then
            python client/setconfig.py
        fi
        supervisorctl restart main
    fi
    sleep 60
done
